<?php
namespace app\home\controller;
use think\Controller;
use think\Db;
use think\Request;
use org\util\HtmlPage;

class Cate extends Controller {
    function index(){
        //----公共部分使用start----//
        $category_list=Db::name('category')->select();
        $article_recent=Db::name('article')->limit(0,9)->order('publictime','desc')->select();
        $this->assign('article_recent',$article_recent);
        $this->assign('category_list',$category_list);
        $article_hot=Db::name('article')->limit(0,9)->order('pv','desc')->select();
        $this->assign('article_hot',$article_hot);
        $image_list=Db::name('image')->select();
        $this->assign('image_list',$image_list);
        //----公共部分使用end----//
        $cate_id=input('get.id');
        //****分页开始****//
        $data['p']=!input('get.p')?1:input('get.p');
        $data['limit']=10;
        $data['total']=Db::name('article')->where('category',$cate_id)->count();
        $data['page_start']=($data['p']-1)*$data['limit'];
        $requset=Request::instance();
        $url=$requset->baseUrl();
        $data['url']=$url.'?id='.$cate_id.'&p=';
        $pagebanner=new HtmlPage($data);
        $this->assign('page_banner',$pagebanner->banner_list());
        //****分页结束****//
        $article_list=Db::name('article')->where('category',$cate_id)->alias('a')->join('category w','a.category=w.id')->field('a.*,w.name')->limit($data['page_start'],$data['limit'])->order('publictime','desc')->select();
        $this->assign('article_list',$article_list);
        return $this->fetch('cate');
    }
}